import { selBusinessID , selUserInfo} from '../services/home'
import {setData} from '../utils/localData'
export default {

  namespace: 'global',

  state: {
      selectedTab: 'blueTab',          //当前选中的是谁
      hidden: false,                  //底部导航是否显示
      fullScreen: false,              //是否全屏幕
      badge:[2,5,'new'],                 //微标数
      BusinessInfo:{},
      userId:''
  },

  subscriptions: {
    setup({ dispatch, history }) {  // eslint-disable-line
    },
  },

  effects: {
    *setBusinessId({ payload }, { call, put }) {  // eslint-disable-line
      console.log("按代理商id查询")
      console.log(payload)
      const resp1 = yield call(selBusinessID,payload)
      const resp2 = yield call(selUserInfo,{})
      console.log("代理商结果")
      console.log(resp1)
      console.log("用户结果")
      console.log(resp2)
      //本地缓存
      if(resp1.data.data){
        setData("businessId",resp1.data.data.businessId)
      }
      if(resp2.data.data){
        setData("userInfo",resp2.data.data)
      }
      yield put(
        { type: 'setGlobal',
          state:{
            BusinessInfo:resp1.data.data,
            userId:resp2.data.data.userId
          }
        }
      );
    },
  },

  reducers: {
    setGlobal(state, action) {
      return { ...state, ...action.state };
    },
  },

};
